package cz.tomasdvorak.cars.dto;

import java.util.Comparator;
import java.util.List;
import java.util.Collections;

public enum ExpenseSort {

    DATE(new Comparator<Expense>() {
        public int compare(Expense o1, Expense o2) {
            return (o1.getDate().compareTo(o2.getDate()));
        }
    });



    private Comparator<Expense> comparator;


    ExpenseSort(Comparator<Expense> comparator) {
        this.comparator = comparator;
    }

    public void sort(List<Expense> data, Boolean asc) {
        Collections.sort(data, this.comparator);
        if (!asc) {
            Collections.reverse(data);
        }
    }
}
